
#pragma once

#include "sync_obj.h"

namespace luc {

#define DECLARE_MEM_POOL(class_name) \
	private: \
		static sync_obj	lock_mem_pool; \
		static list<class_name*> free_chain; \
	public: \
		static void* operator new(size_t _size) { \
			lockit lock(&lock_mem_pool); \
			if (!free_chain.empty()) { \
				class_name* v = free_chain.front(); \
				free_chain.pop_front(); \
				return (void*)v; \
			} else { \
				class_name* v = ::new class_name(); \
				return (void*)v; \
			} \
		} \
		static void operator delete(void* _ptr) { \
			lockit lock(&lock_mem_pool); \
			free_chain.push_back((class_name*)_ptr); \
		}

#define IMPL_MEM_POOL(class_name) \
	sync_obj class_name::lock_mem_pool; \
	list<class_name*> class_name::free_chain;

}
